<?
class Typeunit {
    /**
     *  读出所有分类,在类目管理页(list_type)中使用
     *
     * @access    public
     * @param     int   $table  表名
     * @param     int   $parentid  当前操作ID
     * @return    string
     */
     public function ListType($table,$parentid=0){
        $Form = M($table);
        $list = $Form->where('parentid='.$parentid)->order("sort desc,id asc")->select();
        foreach ($list as $k => $v) {
             echo '<tr align="center"  bgcolor="#FBFCE2" height="22" class="fid"><td width="7%"><span class="jia"></span>ID</td><td width="14%">'.$v['id'].'</td><td width="14%">'.$v['name'].'</td><td>操作</td></tr>';
             $this->ListTypeSeed($table,$v['id']);
         } 
    }
       
    /**
     *  读出子分类
     *
     * @access    public
     * @param     int   $table  表名
     * @param     int   $parentid  当前操作ID
     * @return    string
     */
    private function ListTypeSeed($table,$parentid){
        $Form = M($table);
        $list = $Form->where('parentid='.$parentid)->order("sort desc,id asc")->select();
        if($list){
            echo '<tr align="center"  bgcolor="#FFFFFF" height="22" class="seed"><td colspan="4"><table width="98%">';
            foreach ($list as $k => $v) {
                 echo '<tr align="center" bgcolor="#FAFAF1" height="22"><td width="7%"><span class="jia"></span>ID</td><td width="14%">'.$v['id'].'</td><td width="14%">'.$v['name'].'</td><td>操作</td></tr>';
                 $this->ListTypeSeed("keshi",$v['id']);
             }
            echo '</table></td></tr>';
        }
    }


    /**
     *  获得子类目的递归调用
     *
     * @access    public
     * @param     int  $id  栏目ID
     * @param     string  $step  层级标志
     * @param     bool  $needcheck  权限
     * @return    string
     */
    function LogicListAllSunType($id,$step,$needcheck=true)
    {

        $department = M("department");
        $condition["parentid"] =$id;
        $data = $department->where($condition)->select();
        if ($data) {
            foreach ($data as $k => $v) {
                $typeName = $v["name"];
                $id = $v["id"];
                $order=$v["order"];
                $urltypename=urlencode($typeName);
                $addchildurl=U('Index/catalog_add',array('id'=>$id));

                $htmls = <<<EOT
               <tr height='24' oncontextmenu="CommonMenu(event,this,$id,'$urltypename')">
                <td class='nbline'>
                <table width='98%' border='0' cellspacing='0' cellpadding='0'>
                <tr onMouseMove="javascript:this.bgColor='#FAFCE0';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
                <td width='50%'>
                <input class='np' type='checkbox' name='tids[]' value='$id'>$step
                <img style='cursor:pointer' id='img$id' onClick="LoadSuns('suns$id',$id);"
                src='/Public/images/dedeexplode.gif' width='11' height='11'>
                  <a href='catalog_do.php?cid=$id&dopost=listArchives'> $typeName [ID:$id]</a>(文档：0)
                    <a onclick="AlertMsg('快捷编辑窗口','$id');" href="javascript:;">
                    <img src='/public/images/write2.gif'/></a>
                </td>
                <td align='right'>
                <a href='$addchildurl'>增加子类</a>
                 |<a href='catalog_edit.php?id=$id'>更改</a>
                 |<a href='catalog_do.php?dopost=moveCatalog&typeid=$id'>移动</a>
                 |<a href='catalog_del.php?id=$id&typeoldname=$urltypename'>删除</a>
                 &nbsp; <input type='text' name='sortrank$id' value='$order' style='width:25px;height:20px'>
                 </td></tr>
                 </table>
                 </td></tr>
EOT;
                echo $htmls;
                $this->LogicListAllSunType($id, $step . "　", false);
            }
        }
    }


    /**
     *  读出所有分类,在类目管理页(list_type)中使用
     *
     * @access    public
     * @param     int   $channel  频道ID
     * @param     int   $nowdir  当前操作ID
     * @return    string
     */
    function ListAllType()
    {

        $department = M("department");
        $condition["parentid"] = 0;
        $data = $department->where($condition)->select();
        if ($data) {
            foreach ($data as $k => $v) {

                $typeName = $v["name"];
                $id = $v["id"];

                echo "<table width='100%' border='0' cellspacing='0' cellpadding='2'>\r\n";
                echo "  <tr>\r\n";
                echo "  <td style='background-color:#FBFCE2;' width='2%' class='bline'><img style='cursor:pointer' id='img" . $id . "' onClick=\"LoadSuns('suns" . $id . "',$id);\" src='images/dedeexplode.gif' width='11' height='11'></td>\r\n";
                echo "  <td style='background-color:#FBFCE2;' class='bline'><table width='98%' border='0' cellspacing='0' cellpadding='0'><tr><td width='50%'><input class='np' type='checkbox' name='tids[]' value='{$id}'><a href='catalog_do.php?cid=" . $id . "&dopost=listArchives' oncontextmenu=\"CommonMenu(event,this,$id,'" . urlencode($typeName) . "')\">{$nss}" . $typeName . "[ID:" . $id . "]</a>(文档：" . $this->GetTotalArc($id) . ")  <a onclick=\"AlertMsg('快捷编辑窗口','$id');\" href=\"javascript:;\"><img src='images/write2.gif'/></a>";
                echo "    </td><td align='right'>";
                echo "<a href='{$GLOBALS['cfg_phpurl']}/list.php?tid={$id}' target='_blank'>预览</a>";
                echo "|<a href='catalog_do.php?cid={$id}&dopost=listArchives'>内容</a>";
                echo "|<a href='catalog_add.php?id={$id}'>增加子类</a>";
                echo "|<a href='catalog_edit.php?id={$id}'>更改</a>";
                echo "|<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}'>移动</a>";
                echo "|<a href='catalog_del.php?id={$id}&typeoldname=" . urlencode($typeName) . "'>删除</a>";
                echo "&nbsp; <input type='text' name='sortrank{$id}' value='{$rank}' style='width:25px;height:20px'></td></tr></table></td></tr>\r\n";

                echo "  <tr><td colspan='2' id='suns" . $id . "'>";
                $lastid = GetCookie('lastCid');
                if ($channel == $id || $lastid == $id || isset($GLOBALS['exallct'])) {
                    echo "    <table width='100%' border='0' cellspacing='0' cellpadding='0'>\r\n";
                    $this->LogicListAllSunType($id, "　");
                    echo "    </table>\r\n";
                }
                echo "</td></tr>\r\n</table>\r\n";


            }
        }


    }



}
?>